<script type="text/javascript" src="js/key1.js"></script>
<script type="text/javascript" src="../../js/jquery.watermark.js"></script>
<div class="content-box"><!-- Start Content Box -->
    <div class="content-box-header">
        
        <h3>Sản phẩm</h3>
        
        <input class="span" id="faq_search_input1" type="text" placeholder="Tìm kiếm..." style="width:130px; height:20px; margin:10px; border-radius:5px;">
        
        <ul class="content-box-tabs">
       		
            <li><a href="#tab1" class="default-tab">Table</a></li> <!-- href must be unique and match the id of target div -->
            <li><a href="#tab2">Forms</a></li>
        </ul>
        
        <div class="clear"></div>
        
    </div> <!-- End .content-box-header -->
    
    <div class="content-box-content">
   
        <div class="tab-content default-tab" id="tab1"><!-- This is the target div. id must match the href of this div's tab -->
            <table id="product-table" class="table table-bordered">
                <tr id="sort-row" data-base-url="/admin_vina/product/all">
                    <!--<th></th>-->
                    <th>STT</th>
                    <th data-model="Product" id="product_post_date"><a href="#">Ảnh sản phẩm</a></th>
                    <th data-model="Product" id="product_name"><a href="#">Tên sản phẩm</a></th>
                    <th data-model="Product" id="product_sell_price"><a href="#">Giá bán</a></th>
                    <th data-model="Brand" id="brand_name"><a href="#">Giao hàng</a></th>
                    <th data-model="User" id="user_display_name"><a href="#">Tình trạng</a></th>
                    <th data-model="User" id="user_display_name"><a href="#">Loại</a></th>

                    <th data-model="Product" id="product_code"><a href="#">Chủng loại</a></th>
                    <th data-model="Catalogue" id="catalogue_name"><a href="#">Danh mục</a></th>
                    <th style="width: 150px;">Sửa/ Xóa</th>
                </tr>
            <?php
            $display=10;
                if(isset($_GET['total']) && (int)$_GET['total']){
                    $total = $_GET['total'];
                }else{
                      $query='SELECT COUNT(id) FROM tbl_sanpham';
                      $res = mysql_query($query);
                      $row1=mysql_fetch_array($res);
                      $record = $row1[0];
                      if($record > $display){
                          $total = ceil($record/$display);
                      }else{
                          $total=1;
                      }
                    }
                $start = (isset($_GET['start']) && (int)$_GET['start']>=0)?$_GET['start']:0;
            $i=1;
            $sql="SELECT
                                *
                                FROM tbl_sanpham
                                ORDER BY id ASC LIMIT ".$start.",".$display."";
                $result=mysql_query($sql);
                $num=mysql_num_rows($result);
                if($num>0)
                {
                    while($row=mysql_fetch_array($result))
                        {
                        ?>
                        <tr>
                            <!--<td></td>-->
                            <td><?php echo $i++;?></td>
                            <td style="width: 90px;"><img src="../uploads/<?php echo $row['anhsp'];?>" style="width:40px; height:40px;"/></td>
                            <td><a href="index.php?page=product&act=edit&id=<?php echo $row['id']?>"><?php echo $row['sanpham'];?></a></td>

                            <td style="color: red;"><?php echo $row['gia'];?></td>

                            <td ><?php echo $row['giaohang'];?></td>
                            <td><?php if($row['tinhtrang']==1)echo 'Còn hàng'; else echo 'Hết hàng';?></td>
                            <td><?php   $sql_l=mysql_query('SELECT * FROM tbl_loai WHERE loai_id="'.$row['loai_id'].'"');
                                        $row_l=mysql_fetch_array($sql_l);
                                echo $row_l['loai'];?></td>
                            <td><?php   $sql_cl=mysql_query('SELECT * FROM tbl_chungloai WHERE chungloai_id="'.$row['chungloai_id'].'"');
                                        $row_cl=mysql_fetch_array($sql_cl);
                                echo $row_cl['chungloai'];?></td>
                            <td><?php   $sql_dm=mysql_query('SELECT * FROM tbl_danhmuc WHERE danhmuc_id="'.$row['danhmuc_id'].'"');
                                        $row_dm=mysql_fetch_array($sql_dm);
                                echo $row_dm['danhmuc'];?></td>
                            <td style="width: 150px;">
                                <a href="index.php?page=product&act=edit&id=<?php echo $row['id'];?>" title="Edit">Sửa</a> |
                                     <a href="index.php?page=product&act=del&id=<?php echo $row['id'];?>" title="Delete"   onclick="return confirmSubmit()" class="del" style="color: #ff654f">Xóa</a>
                            </td>
                         </tr>
                         <?php
                        }
                        ?>
                        <tr>
                        <?php
                            if($total>1)
                            {
                                $next=$start + $display;
                                $prev=$start - $display;
                                $current=($start/$display)+1;
                        ?>
                            <td colspan="10">

                                <div class="pagination" style="height:50px;">
                                <?php
                                    //Hiển thị prev
                                    if($current !=1)
                                    {
                                        echo '<a href="index.php?page=product&start='.$prev.'" title="Previous Page">&laquo; Previous</a>';
                                    }
                                    //Hiển thị phân trang trong
                                    for($i=1;$i<=$total;$i++)
                                    {
                                        if($current!=$i)
                                        {
                                            echo '<a href="index.php?page=product&start='.($display*($i-1)).'" class="number" title="1">'.$i.'</a>';
                                        }else
                                            {
                                                echo '<a class="number current">'.$i.'</a>';
                                            }
                                    }
                                    //Hiển thị next
                                    if($current !=$total)
                                    {
                                        echo '<a href="index.php?page=product&start='.$next.'" title="Next Page">Next &raquo;</a>';
                                    }
                                ?>
                                </div> <!-- End .pagination -->
                                <div class="clear"></div>
                            </td>
                            <?php
                            }
                            ?>
                        </tr>
                        <?php
                }
                 ?>
           </table>
            </div> <!-- End #tab1 -->
     <!-- End .content-box-content -->
    
</div> <!-- End .content-box -->
</div>
<script LANGUAGE="JavaScript">
    function confirmSubmit()
    {
        var agree=confirm("Bạn có chắc chắn xóa không?");
        if (agree)
            return true ;
        else
            return false ;
    }
</script>